// var a = cc._decorator;
// var s = a.ccclass;
// var r =
//     (a.property,
//     (function () {
//         function e() {}
//         e.prototype.chuangjian_fengjin_yuzhiti = function () {
//             var e = new cc.Node("fengjingDialog");
//             e.width = cc.winSize.width;
//             e.height = cc.winSize.height;
//             e.addComponent(cc.Sprite);
//             e.addComponent(cc.BlockInputEvents);
//             e.color = cc.Color.BLACK;
//             e.opacity = 200;
//             this.tianjia_jingling_tu(e, "Flower/img/common/whiteBg", cc.Sprite.Type.SIMPLE, cc.Sprite.SizeMode.CUSTOM);
//             var t = new cc.Node("text");
//             t.addComponent(cc.Sprite);
//             this.tianjia_jingling_tu(t, "Flower/img/common/fengjing");
//             e.x = 0.5 * cc.winSize.width;
//             e.y = 0.5 * cc.winSize.height;
//             cc.director.getScene().addChild(e);
//             cc.game.addPersistRootNode(e);
//             e.zIndex = 9999999;
//             if (cc.winSize.width < 768) {
//                 t.scale = cc.winSize.width / 768;
//             }
//             e.addChild(t);
//             var o = new cc.Node("kefu");
//             o.y = -213.969;
//             o.addComponent(cc.Sprite);
//             this.tianjia_jingling_tu(o, "Flower/img/common/btnFJ");
//             o.addComponent(cc.Button);
//             o.on("click", function () {
//                 var e = window.wx;
//                 if (e) {
//                     e.openCustomerServiceConversation({
//                         success: function () {
//                             console.log("成功打开客服对话框");
//                         },
//                         fail: function (e) {
//                             console.error("打开客服对话框失败：", e);
//                         }
//                     });
//                 }
//             });
//             t.addChild(o);
//             return e;
//         };
//         e.prototype.chuangjian_shoucang_yuzhiti = function (e) {
//             var t = new cc.Node();
//             var o = new cc.Node("fengjingDialog");
//             o.width = cc.winSize.width;
//             o.height = cc.winSize.height;
//             o.addComponent(cc.Sprite);
//             o.addComponent(cc.BlockInputEvents);
//             o.color = cc.Color.BLACK;
//             o.opacity = 200;
//             t.addChild(o);
//             this.tianjia_jingling_tu(o, "Flower/img/common/whiteBg", cc.Sprite.Type.SIMPLE, cc.Sprite.SizeMode.CUSTOM);
//             var i = new cc.Node("text");
//             i.addComponent(cc.Sprite);
//             this.tianjia_jingling_tu(i, "Flower/img/addToFavorites/img");
//             t.x = 0.5 * cc.winSize.width;
//             t.y = 0.5 * cc.winSize.height;
//             cc.director.getScene().addChild(t);
//             cc.game.addPersistRootNode(t);
//             t.zIndex = 9999999;
//             if (cc.winSize.width < 768) {
//                 i.scale = cc.winSize.width / 768;
//             }
//             t.addChild(i);
//             var n = new cc.Node("kefu");
//             n.y = -348;
//             n.addComponent(cc.Sprite);
//             this.tianjia_jingling_tu(n, "Flower/img/addToFavorites/get_btn");
//             n.addComponent(cc.Button);
//             n.on("click", function () {
//                 var t = window.wx;
//                 var o = user_default.get_int_for_key("ly_wx_shoucang", 0);
//                 1 == o
//                     ? e && e(1)
//                     : (t.showToast({
//                           title: 0 == o ? "请先收藏游戏" : "已领取",
//                           icon: "none",
//                           duration: 500
//                       }),
//                       e && e(0));
//             });
//             var a = new cc.Node();
//             a.width = 24;
//             a.height = 24;
//             a.x = 260;
//             a.y = 380;
//             this.tianjia_jingling_tu(
//                 a,
//                 "Flower/img/addToFavorites/close_btn",
//                 cc.Sprite.Type.SIMPLE,
//                 cc.Sprite.SizeMode.CUSTOM
//             );
//             a.addComponent(cc.Button);
//             a.on("click", function () {
//                 t.destroy();
//             });
//             i.addChild(a);
//             i.addChild(n);
//             return t;
//         };
//         e.prototype.tianjia_jingling_tu = function (e, t, o, i) {
//             if (void 0 === o) {
//                 o = cc.Sprite.Type.SIMPLE;
//             }
//             if (void 0 === i) {
//                 i = cc.Sprite.SizeMode.TRIMMED;
//             }
//             console.log("tianjia_jingling_tu", e, t);
//             var n = e.getComponent(cc.Sprite) ? e.getComponent(cc.Sprite) : e.addComponent(cc.Sprite);
//             n.type = o;
//             n.sizeMode = i;
//             if (t) {
//                 cc.loader.loadRes(t, cc.SpriteFrame, function (e, t) {
//                     e ? console.log("tianjia_jingling_tu err: ", JSON.stringify(e)) : (n.spriteFrame = t);
//                 });
//             }
//         };
//         return __decorate([s], e);
//     })());
// exports.default = r;


const { ccclass, property } = cc._decorator;

/**
 * @class FengjinPrefabManager
 * @description 管理封禁预制体的创建和相关操作
 */
@ccclass
class FengjinPrefabManager {

    /**
     * @function chuangjian_fengjin_yuzhiti
     * @description 创建封禁对话框预制体
     * @returns {cc.Node} 返回创建的封禁预制体节点
     */
    chuangjian_fengjin_yuzhiti() {
        const fengjingDialogNode = new cc.Node("fengjingDialog");
        fengjingDialogNode.width = cc.winSize.width;
        fengjingDialogNode.height = cc.winSize.height;
        fengjingDialogNode.addComponent(cc.Sprite);
        fengjingDialogNode.addComponent(cc.BlockInputEvents);
        fengjingDialogNode.color = cc.Color.BLACK;
        fengjingDialogNode.opacity = 200;
        this.tianjia_jingling_tu(fengjingDialogNode, "Flower/img/common/whiteBg", cc.Sprite.Type.SIMPLE, cc.Sprite.SizeMode.CUSTOM);

        const textNode = new cc.Node("text");
        textNode.addComponent(cc.Sprite);
        this.tianjia_jingling_tu(textNode, "Flower/img/common/fengjing");

        fengjingDialogNode.x = 0.5 * cc.winSize.width;
        fengjingDialogNode.y = 0.5 * cc.winSize.height;
        cc.director.getScene().addChild(fengjingDialogNode);
        cc.game.addPersistRootNode(fengjingDialogNode);
        fengjingDialogNode.zIndex = 9999999;

        if (cc.winSize.width < 768) {
            textNode.scale = cc.winSize.width / 768;
        }

        fengjingDialogNode.addChild(textNode);

        const kefuNode = new cc.Node("kefu");
        kefuNode.y = -213.969;
        kefuNode.addComponent(cc.Sprite);
        this.tianjia_jingling_tu(kefuNode, "Flower/img/common/btnFJ");
        kefuNode.addComponent(cc.Button);
        kefuNode.on("click", () => {
            const wx = window.wx;
            if (wx) {
                wx.openCustomerServiceConversation({
                    success: () => {
                        console.log("成功打开客服对话框");
                    },
                    fail: (error) => {
                        console.error("打开客服对话框失败：", error);
                    }
                });
            }
        });

        textNode.addChild(kefuNode);
        return fengjingDialogNode;
    }

    /**
     * @function chuangjian_shoucang_yuzhiti
     * @description 创建收藏对话框预制体
     * @param {Function} callback 点击按钮后的回调函数
     * @returns {cc.Node} 返回创建的收藏预制体节点
     */
    chuangjian_shoucang_yuzhiti(callback) {
        const rootNode = new cc.Node();
        const dialogNode = new cc.Node("fengjingDialog");
        dialogNode.width = cc.winSize.width;
        dialogNode.height = cc.winSize.height;
        dialogNode.addComponent(cc.Sprite);
        dialogNode.addComponent(cc.BlockInputEvents);
        dialogNode.color = cc.Color.BLACK;
        dialogNode.opacity = 200;
        rootNode.addChild(dialogNode);
        this.tianjia_jingling_tu(dialogNode, "Flower/img/common/whiteBg", cc.Sprite.Type.SIMPLE, cc.Sprite.SizeMode.CUSTOM);

        const textNode = new cc.Node("text");
        textNode.addComponent(cc.Sprite);
        this.tianjia_jingling_tu(textNode, "Flower/img/addToFavorites/img");

        rootNode.x = 0.5 * cc.winSize.width;
        rootNode.y = 0.5 * cc.winSize.height;
        cc.director.getScene().addChild(rootNode);
        cc.game.addPersistRootNode(rootNode);
        rootNode.zIndex = 9999999;

        if (cc.winSize.width < 768) {
            textNode.scale = cc.winSize.width / 768;
        }

        rootNode.addChild(textNode);

        const kefuNode = new cc.Node("kefu");
        kefuNode.y = -348;
        kefuNode.addComponent(cc.Sprite);
        this.tianjia_jingling_tu(kefuNode, "Flower/img/addToFavorites/get_btn");
        kefuNode.addComponent(cc.Button);
        kefuNode.on("click", () => {
            const wx = window.wx;
            const isFavorited = user_default.get_int_for_key("ly_wx_shoucang", 0);
            if (isFavorited === 1) {
                callback && callback(1);
            } else {
                wx.showToast({
                    title: isFavorited === 0 ? "请先收藏游戏" : "已领取",
                    icon: "none",
                    duration: 500
                });
                callback && callback(0);
            }
        });

        const closeButtonNode = new cc.Node();
        closeButtonNode.width = 24;
        closeButtonNode.height = 24;
        closeButtonNode.x = 260;
        closeButtonNode.y = 380;
        this.tianjia_jingling_tu(closeButtonNode, "Flower/img/addToFavorites/close_btn", cc.Sprite.Type.SIMPLE, cc.Sprite.SizeMode.CUSTOM);
        closeButtonNode.addComponent(cc.Button);
        closeButtonNode.on("click", () => {
            rootNode.destroy();
        });

        textNode.addChild(closeButtonNode);
        textNode.addChild(kefuNode);

        return rootNode;
    }

    /**
     * @function tianjia_jingling_tu
     * @description 给节点添加精灵组件并加载精灵帧
     * @param {cc.Node} node 需要添加精灵组件的节点
     * @param {string} spritePath 精灵帧的路径
     * @param {cc.Sprite.Type} spriteType 精灵的类型
     * @param {cc.Sprite.SizeMode} sizeMode 精灵的尺寸模式
     */
    tianjia_jingling_tu(node, spritePath, spriteType = cc.Sprite.Type.SIMPLE, sizeMode = cc.Sprite.SizeMode.TRIMMED) {
        console.log("tianjia_jingling_tu", node, spritePath);
        const spriteComponent = node.getComponent(cc.Sprite) || node.addComponent(cc.Sprite);
        spriteComponent.type = spriteType;
        spriteComponent.sizeMode = sizeMode;

        if (spritePath) {
            cc.loader.loadRes(spritePath, cc.SpriteFrame, (error, spriteFrame) => {
                if (error) {
                    console.log("tianjia_jingling_tu err: ", JSON.stringify(error));
                } else {
                    spriteComponent.spriteFrame = spriteFrame;
                }
            });
        }
    }
}

export default FengjinPrefabManager;
